package com.ruoyi.project.good.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.good.domain.GoodsForwardRecord;
import com.ruoyi.project.good.service.IGoodsForwardRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品转发Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@RestController
@RequestMapping("/good/record")
public class GoodsForwardRecordController extends BaseController
{
    @Autowired
    private IGoodsForwardRecordService goodsForwardRecordService;

    /**
     * 查询商品转发列表
     */
    @PreAuthorize("@ss.hasPermi('good:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsForwardRecord goodsForwardRecord)
    {
        startPage();
        List<GoodsForwardRecord> list = goodsForwardRecordService.selectGoodsForwardRecordList(goodsForwardRecord);
        return getDataTable(list);
    }

    /**
     * 导出商品转发列表
     */
    @PreAuthorize("@ss.hasPermi('good:record:export')")
    @Log(title = "商品转发", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsForwardRecord goodsForwardRecord)
    {
        List<GoodsForwardRecord> list = goodsForwardRecordService.selectGoodsForwardRecordList(goodsForwardRecord);
        ExcelUtil<GoodsForwardRecord> util = new ExcelUtil<GoodsForwardRecord>(GoodsForwardRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 获取商品转发详细信息
     */
    @PreAuthorize("@ss.hasPermi('good:record:query')")
    @GetMapping(value = "/{forwardId}")
    public AjaxResult getInfo(@PathVariable("forwardId") Long forwardId)
    {
        return AjaxResult.success(goodsForwardRecordService.selectGoodsForwardRecordById(forwardId));
    }

    /**
     * 新增商品转发
     */
    @PreAuthorize("@ss.hasPermi('good:record:add')")
    @Log(title = "商品转发", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsForwardRecord goodsForwardRecord)
    {
        return toAjax(goodsForwardRecordService.insertGoodsForwardRecord(goodsForwardRecord));
    }

    /**
     * 修改商品转发
     */
    @PreAuthorize("@ss.hasPermi('good:record:edit')")
    @Log(title = "商品转发", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsForwardRecord goodsForwardRecord)
    {
        return toAjax(goodsForwardRecordService.updateGoodsForwardRecord(goodsForwardRecord));
    }

    /**
     * 删除商品转发
     */
    @PreAuthorize("@ss.hasPermi('good:record:remove')")
    @Log(title = "商品转发", businessType = BusinessType.DELETE)
	@DeleteMapping("/{forwardIds}")
    public AjaxResult remove(@PathVariable Long[] forwardIds)
    {
        return toAjax(goodsForwardRecordService.deleteGoodsForwardRecordByIds(forwardIds));
    }
}
